# -*- coding: utf-8 -*-
# created on 2017/3/1


from mathsolver.functions.base import *


# 更新二项式
class EXSPolyUpdate(BaseFunction):
    def solver(self, *args):
        poly = args[0].sympify()
        exs = BaseErXiangShi(poly)
        self.output.append(exs)
        return self


class EXSEqUpdate(BaseFunction):
    def solver(self, *args):
        eq = args[0].sympify()
        expr = (eq[0] - eq[1]).simplify().expand()
        expr_symbols = expr.free_symbols
        for symbol in expr_symbols:
            symbol_value = self.search(str(symbol))
            for value in symbol_value:
                expr = expr.subs({symbol: value})
        answer = {"Eequations": [[expr, S.Zero]]}
        self.steps.append(["", "∴%s" % (BaseEq([expr, S.Zero]).printing())])
        self.output.append(BaseErXiangShiValue(answer))
        return self
